package com.yao.longhan.ui.activity;

import android.os.Bundle;
import android.support.annotation.IdRes;
import android.widget.RadioGroup;
import android.widget.TextView;

import com.yao.longhan.R;
import com.yao.longhan.ui.base.BaseActivity;
import com.yao.longhan.ui.fragment.FragmentController;

import butterknife.BindView;

/**
 * Created by heyao on 2017/7/17....
 */

public class MainActivity extends BaseActivity implements RadioGroup.OnCheckedChangeListener {

    @BindView(R.id.hometab_radio)
    RadioGroup homeRadio;

    @BindView(R.id.tv_home_title)
    TextView tvTitle;

    private FragmentController mController;

    @Override
    protected int inflateLayout() {
        return R.layout.activity_main;
    }

    @Override
    protected void initView(Bundle savedInstanceState) {
        super.initView(savedInstanceState);
        homeRadio.setOnCheckedChangeListener(this);
    }

    @Override
    protected void initAfter() {
        mController = FragmentController.instance(this, R.id.hometab_context);
        mController.showFragment(0);
    }

    @Override
    public void onCheckedChanged(RadioGroup radioGroup, @IdRes int i) {
        switch (i) {
            case R.id.rb_recommend:
                tvTitle.setText(R.string.home_bookcase);
                mController.showFragment(0);
                break;
            case R.id.rb_stack:
                tvTitle.setText(R.string.home_bookstore);
                mController.showFragment(1);
                break;
            case R.id.rb_download:
                tvTitle.setText(R.string.home_myself);
                mController.showFragment(2);
                break;
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        FragmentController.onDestroy();
    }
}
